package com.hy.erp.inventory.service;

import java.util.List ;

import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;
import org.jboss.seam.async.Schedule ;

import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.interfaces.IPostcodeDao;
import com.hy.erp.inventory.dao.interfaces.IUserDao;
import com.hy.erp.inventory.pojo.Postcode;
import com.hy.erp.inventory.pojo.interfaces.IPostcode;
import com.hy.erp.inventory.pojo.interfaces.IUser;
import com.hy.erp.inventory.service.interfaces.IPostcodeService;
/**
 * 
 * <ul>
 * <li>开发作者：汤莉</li>
 * <li>设计日期：2010-10-13；时间：上午11:28:03</li>
 * <li>类型名称：PostcodeService</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
@Name("postcodeService")
@ Scope ( ScopeType.STATELESS )
@ Stateless
public class PostcodeService
							extends
							AbstractBusinessService < IPostcode >
																	implements
																	IPostcodeService
{

	/**
	 * <ul>
	 * <li>开发作者：汤莉</li>
	 * <li>设计日期：2010-10-13；时间：上午11:28:15</li>
	 * <li>字段类型：long；字段名称：serialVersionUID</li>
	 * <li>设计目的：</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 */
	private static final long	serialVersionUID	=
														3156764481655541467L ;
	/**
	 * 
	 * 构造函数
	 */
	public PostcodeService()
	{
		super ( );
	}
	
	@ Override
	public boolean addPostcode (
									Postcode postcode )
	{
		if(postcode==null)
		{
			return true;
		}
		else
		{
			IPostcodeDao dao=( IPostcodeDao ) this.getDao ( IPostcode.class );
			IPostcode iPostcode= postcode;
			return dao.persist ( iPostcode ) ;
		}
	}

	@ Override
	public Integer removePostcode (
									String [ ] Ids )
	{
		if ( ( null == Ids )
			     || ( Ids.length == 0 ) )
			{
				return new Integer (
				                     0 ) ;
			}
			else
			{
				IPostcodeDao dao=( IPostcodeDao ) this.getDao ( IPostcode.class );
				return dao.remove ( Ids );
			}
	}

	@ SuppressWarnings ( "unused" )
	@ Override
	public boolean modifyPostcode (
									Postcode postcode )
	{
		if ( ( null == postcode ) || ( null == postcode.getIdentifier ( ) ))
		{
			return true;
		}
		else
		{
			IPostcodeDao dao=( IPostcodeDao ) this.getDao ( IPostcode.class );
			IPostcode iPostcode= postcode;
			
			if ( null == iPostcode)
			{
				throw new ArchitectureFoundationException (
				                                            "修改用户实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
			}
			return (dao.merge ( iPostcode )!=null) ;
		}
	}

	@ Override
	public String [ ] addPostcode (
									Object [ ] objects )
	{
		IPostcodeDao dao=( IPostcodeDao ) this.getDao ( IPostcode.class );
		Postcode[] postcodes=new Postcode[objects.length];
		for ( int i =
						0 ; i < objects.length ; i ++ )
		{
			Postcode postcode=( Postcode ) objects[i];
			postcodes[i]=postcode;
		}
		return dao.persist ( postcodes ) ;
	}

	@ Override
	public List < IPostcode > getAllPostCode ( )
	{
		IPostcodeDao dao=( IPostcodeDao ) this.getDao ( IPostcode.class );
		return dao.find ( ) ;
	}

	@ Override
	public String [ ] modifyPostcode (
										Object [ ] objects )
	{

		if (  null == objects ) 
				{
					return null;
				}
				else
				{
					IPostcodeDao dao=( IPostcodeDao ) this.getDao ( IPostcode.class );
					Postcode[] types=new Postcode[objects.length];
		            for(int i=0;i<objects.length;i++)
		            {
		            	Postcode type=( Postcode ) objects[i];
		            	types[i]=type;
		            }
					
					return dao.merge ( types );
				}
	}

}
